-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Revert "[NFC][Flang] Move bounds helper functions to Util header." #158654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-fir-hlfir Author: Akash Banerjee (TIFitis) ChangesReverts llvm/llvm-project#154164 Full diff: https://github.com/llvm/llvm-project/pull/158654.diff 4 Files Affected:
diff --git a/flang/include/flang/Optimizer/OpenMP/Utils.h b/flang/include/flang/Optimizer/OpenMP/Utils.h
index 235e667130659..636c768b016b7 100644
--- a/flang/include/flang/Optimizer/OpenMP/Utils.h
+++ b/flang/include/flang/Optimizer/OpenMP/Utils.h
@@ -13,17 +13,6 @@
#ifndef FORTRAN_OPTIMIZER_OPENMP_UTILS_H
#define FORTRAN_OPTIMIZER_OPENMP_UTILS_H
-#include "flang/Optimizer/Builder/BoxValue.h"
-#include "flang/Optimizer/Builder/DirectivesCommon.h"
-#include "flang/Optimizer/Builder/FIRBuilder.h"
-#include "flang/Optimizer/Builder/HLFIRTools.h"
-#include "flang/Optimizer/Dialect/FIRType.h"
-
-#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
-#include "mlir/IR/Value.h"
-
-#include "llvm/ADT/SmallVector.h"
-
namespace flangomp {
enum class DoConcurrentMappingKind {
@@ -32,35 +21,6 @@ enum class DoConcurrentMappingKind {
DCMK_Device ///< Lower to run in parallel on the GPU.
};
-/// Return true if the variable has a dynamic size and therefore requires
-/// bounds operations to describe its extents.
-inline bool needsBoundsOps(mlir::Value var) {
- assert(mlir::isa<mlir::omp::PointerLikeType>(var.getType()) &&
- "needsBoundsOps can deal only with pointer types");
- mlir::Type t = fir::unwrapRefType(var.getType());
- if (mlir::Type inner = fir::dyn_cast_ptrOrBoxEleTy(t))
- return fir::hasDynamicSize(inner);
- return fir::hasDynamicSize(t);
-}
-
-/// Generate MapBoundsOp operations for the variable and append them to
-/// `boundsOps`.
-inline llvm::SmallVector<mlir::Value> genBoundsOps(fir::FirOpBuilder &builder,
- mlir::Value var,
- bool isAssumedSize = false,
- bool isOptional = false) {
- mlir::Location loc = var.getLoc();
- fir::factory::AddrAndBoundsInfo info =
- fir::factory::getDataOperandBaseAddr(builder, var, isOptional, loc);
- fir::ExtendedValue exv =
- hlfir::translateToExtendedValue(loc, builder, hlfir::Entity{info.addr},
- /*contiguousHint=*/true)
- .first;
- return fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
- mlir::omp::MapBoundsType>(
- builder, info, exv, isAssumedSize, loc);
-}
-
} // namespace flangomp
#endif // FORTRAN_OPTIMIZER_OPENMP_UTILS_H
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 9279bc04e7daf..0ec33e6b24dbf 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -30,7 +30,6 @@
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/HLFIR/HLFIROps.h"
-#include "flang/Optimizer/OpenMP/Utils.h"
#include "flang/Parser/characters.h"
#include "flang/Parser/openmp-utils.h"
#include "flang/Parser/parse-tree.h"
@@ -2497,10 +2496,12 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
Fortran::lower::getDataOperandBaseAddr(
converter, firOpBuilder, sym.GetUltimate(),
converter.getCurrentLocation());
- llvm::SmallVector<mlir::Value> bounds = flangomp::genBoundsOps(
- firOpBuilder, info.rawInput,
- semantics::IsAssumedSizeArray(sym.GetUltimate()),
- semantics::IsOptional(sym.GetUltimate()));
+ llvm::SmallVector<mlir::Value> bounds =
+ fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
+ mlir::omp::MapBoundsType>(
+ firOpBuilder, info, dataExv,
+ semantics::IsAssumedSizeArray(sym.GetUltimate()),
+ converter.getCurrentLocation());
mlir::Value baseOp = info.rawInput;
mlir::Type eleType = baseOp.getType();
if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
diff --git a/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
index d4be315c167be..8b9991301aae8 100644
--- a/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
+++ b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
@@ -13,7 +13,6 @@
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
#include "flang/Optimizer/HLFIR/HLFIROps.h"
-#include "flang/Optimizer/OpenMP/Utils.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
@@ -34,6 +33,36 @@ namespace {
class AutomapToTargetDataPass
: public flangomp::impl::AutomapToTargetDataPassBase<
AutomapToTargetDataPass> {
+
+ // Returns true if the variable has a dynamic size and therefore requires
+ // bounds operations to describe its extents.
+ inline bool needsBoundsOps(mlir::Value var) {
+ assert(mlir::isa<mlir::omp::PointerLikeType>(var.getType()) &&
+ "only pointer like types expected");
+ mlir::Type t = fir::unwrapRefType(var.getType());
+ if (mlir::Type inner = fir::dyn_cast_ptrOrBoxEleTy(t))
+ return fir::hasDynamicSize(inner);
+ return fir::hasDynamicSize(t);
+ }
+
+ // Generate MapBoundsOp operations for the variable if required.
+ inline void genBoundsOps(fir::FirOpBuilder &builder, mlir::Value var,
+ llvm::SmallVectorImpl<mlir::Value> &boundsOps) {
+ mlir::Location loc = var.getLoc();
+ fir::factory::AddrAndBoundsInfo info =
+ fir::factory::getDataOperandBaseAddr(builder, var,
+ /*isOptional=*/false, loc);
+ fir::ExtendedValue exv =
+ hlfir::translateToExtendedValue(loc, builder, hlfir::Entity{info.addr},
+ /*contiguousHint=*/true)
+ .first;
+ llvm::SmallVector<mlir::Value> tmp =
+ fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
+ mlir::omp::MapBoundsType>(
+ builder, info, exv, /*dataExvIsAssumedSize=*/false, loc);
+ llvm::append_range(boundsOps, tmp);
+ }
+
void findRelatedAllocmemFreemem(fir::AddrOfOp addressOfOp,
llvm::DenseSet<fir::StoreOp> &allocmems,
llvm::DenseSet<fir::LoadOp> &freemems) {
@@ -83,8 +112,8 @@ class AutomapToTargetDataPass
auto addMapInfo = [&](auto globalOp, auto memOp) {
builder.setInsertionPointAfter(memOp);
SmallVector<Value> bounds;
- if (flangomp::needsBoundsOps(memOp.getMemref()))
- bounds = flangomp::genBoundsOps(builder, memOp.getMemref());
+ if (needsBoundsOps(memOp.getMemref()))
+ genBoundsOps(builder, memOp.getMemref(), bounds);
omp::TargetEnterExitUpdateDataOperands clauses;
mlir::omp::MapInfoOp mapInfo = mlir::omp::MapInfoOp::create(
diff --git a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
index 5c1a3d232a8c9..30328573b74fc 100644
--- a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
+++ b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
@@ -29,7 +29,6 @@
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
#include "flang/Optimizer/HLFIR/HLFIROps.h"
#include "flang/Optimizer/OpenMP/Passes.h"
-#include "flang/Optimizer/OpenMP/Utils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -107,8 +106,8 @@ class MapsForPrivatizedSymbolsPass
// Figure out the bounds because knowing the bounds will help the subsequent
// MapInfoFinalizationPass map the underlying data of the descriptor.
llvm::SmallVector<mlir::Value> boundsOps;
- if (flangomp::needsBoundsOps(varPtr))
- boundsOps = flangomp::genBoundsOps(builder, varPtr);
+ if (needsBoundsOps(varPtr))
+ genBoundsOps(builder, varPtr, boundsOps);
mlir::omp::VariableCaptureKind captureKind =
mlir::omp::VariableCaptureKind::ByRef;
@@ -195,5 +194,38 @@ class MapsForPrivatizedSymbolsPass
}
}
}
+ // As the name suggests, this function examines var to determine if
+ // it has dynamic size. If true, this pass'll have to extract these
+ // bounds from descriptor of var and add the bounds to the resultant
+ // MapInfoOp.
+ bool needsBoundsOps(mlir::Value var) {
+ assert(mlir::isa<omp::PointerLikeType>(var.getType()) &&
+ "needsBoundsOps can deal only with pointer types");
+ mlir::Type t = fir::unwrapRefType(var.getType());
+ // t could be a box, so look inside the box
+ auto innerType = fir::dyn_cast_ptrOrBoxEleTy(t);
+ if (innerType)
+ return fir::hasDynamicSize(innerType);
+ return fir::hasDynamicSize(t);
+ }
+
+ void genBoundsOps(fir::FirOpBuilder &builder, mlir::Value var,
+ llvm::SmallVector<mlir::Value> &boundsOps) {
+ mlir::Location loc = var.getLoc();
+ fir::factory::AddrAndBoundsInfo info =
+ fir::factory::getDataOperandBaseAddr(builder, var,
+ /*isOptional=*/false, loc);
+ fir::ExtendedValue extendedValue =
+ hlfir::translateToExtendedValue(loc, builder, hlfir::Entity{info.addr},
+ /*continguousHint=*/true)
+ .first;
+ llvm::SmallVector<mlir::Value> boundsOpsVec =
+ fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
+ mlir::omp::MapBoundsType>(
+ builder, info, extendedValue,
+ /*dataExvIsAssumedSize=*/false, loc);
+ for (auto bounds : boundsOpsVec)
+ boundsOps.push_back(bounds);
+ }
};
} // namespace
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #154164